package com.zzptc.tkfate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.zzptc.tkfate.R;
import com.zzptc.tkfate.databinding.ReItemBinding;
import com.zzptc.tkfate.entity.ResultsBean;

import org.litepal.LitePal;

import java.util.List;

public class MyRvAdapter extends RecyclerView.Adapter<MyRvAdapter.ViewHoder> {
    private final List<ResultsBean> resultsBeans;
    private final Context mContext;

    public MyRvAdapter(Context mContext){
        resultsBeans = LitePal.findAll(ResultsBean.class);
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public ViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.re_item,parent,false);
        ReItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.re_item, parent, false);

        return new ViewHoder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHoder holder, int position) {
        ResultsBean result = resultsBeans.get(position);
        holder.binding.tvTitle.setText(result.getTitle());
        Glide.with(mContext).load(result.getCover()).into(holder.binding.ivGover);

    }

    @Override
    public int getItemCount() {
        return resultsBeans.size();
    }

    public class ViewHoder extends RecyclerView.ViewHolder {
        private final ReItemBinding binding;
        public ViewHoder(@NonNull ReItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
